package com.example.photography.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.photography.Activity.GroupActivity;
import com.example.photography.R;
import com.example.photography.util.Util;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
/**
 * RecyclerView的label适配器
 * 作品分类标签
 */

public class LabelAdapter extends RecyclerView.Adapter<LabelAdapter.ViewHolder> {
    private List<String> extras;
    private Context context;

    public LabelAdapter(Context context,List<String> extras) {
        this.context = context;
        this.extras = extras;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_label, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.tvLabel.setText("#"+extras.get(position)+"#");
        holder.tvLabel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Util.showToast(context,"关注了第"+position+"个item用户");
                Intent intent = new Intent(context, GroupActivity.class);
                context.startActivity(intent);
            }
        });
    }
    @Override
    public int getItemCount() {
        return extras == null? 0 :extras.size();
    }

    static
    class ViewHolder extends  RecyclerView.ViewHolder{
        @BindView(R.id.tv_label)
        TextView tvLabel;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
